#include <iostream>

using namespace std;

static bool palindrome_decimal(int num) {
    if (num % 10 == 0) 
        return false;    
    int n = num;
    int r = 0;
    while (n > 0) {
        r = r * 10 + n % 10;
        n /= 10;
    }
    return r == num;
}

static bool palindrome_binary(int num) {
    if (num % 2 == 0) 
        return false;    
    int n = num;
    int r = 0;
    while (n > 0) {
        r = r * 2 + n % 2;
        n /= 2;
    }
    return r == num;
}

int main() {
    int s = 0;
    for (int i = 1; i < 1000000; ++i) {
        if (palindrome_decimal(i) && palindrome_binary(i)) {
            cout << i << endl;
            s += i;
        }
    }
    cout << s << endl; // 872187
}